/**
 * @file       Thread_test.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 19, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "Thread.h"
#include "gtest/gtest.h"
#include "MockThread.h"
#include "typedefine.h"
#include "errorcode.h"
namespace NS_LCD_AFW
{
class CThread_test : public ::testing::Test
{
public:
	virtual void SetUp()
	{
	}
	virtual void TearDown()
	{
	}
};
TEST_F(CThread_test,test_defualtConstruction)
{
	CThread *pThread = new CMockThread();
	EXPECT_TRUE(pThread->isAutoDelete());
	EXPECT_FALSE(pThread->isRunning());

	OBJ_DELETE(pThread);
}
TEST_F(CThread_test,test_Construction_2)
{
	CThread *pThread = new CMockThread(true);
	EXPECT_TRUE(pThread->isAutoDelete());
	EXPECT_FALSE(pThread->isRunning());
	OBJ_DELETE(pThread);
	pThread = new CMockThread(false);
	EXPECT_FALSE(pThread->isAutoDelete());
	EXPECT_FALSE(pThread->isRunning());
	OBJ_DELETE(pThread);
}
TEST_F(CThread_test,test_start)
{
	CThread *pThread = new CMockThread(false);
	EXPECT_FALSE(pThread->isAutoDelete());
	EXPECT_FALSE(pThread->isRunning());
	EXPECT_EQ(0,pThread->start());
	EXPECT_EQ(ERR_THREAD_IS_RUNNING,pThread->start());
	EXPECT_TRUE(pThread->isRunning());
	EXPECT_EQ(ERR_SUCCESS,pThread->stop());
	EXPECT_FALSE(pThread->isRunning());
	OBJ_DELETE(pThread);
}
TEST_F(CThread_test,test_join)
{
	CThread *pThread = new CMockThread(false);
	EXPECT_FALSE(pThread->isAutoDelete());
	EXPECT_FALSE(pThread->isRunning());

	EXPECT_EQ(ERR_THREAD_NOT_RUNNING, pThread->join());

	EXPECT_EQ(0,pThread->start());
	EXPECT_TRUE(pThread->isRunning());
	EXPECT_EQ(0, pThread->join());
	EXPECT_EQ(ERR_SUCCESS, pThread->stop());
	EXPECT_FALSE(pThread->isRunning());
	OBJ_DELETE(pThread);

}
} /* namespace NS_LCD_AFW */
